import { wxRequest } from '../../utils/server.js';  
const _wxRequest = new wxRequest();
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    typeIndex:0,
    uploadUrl: wx.getStorageSync('uploadUrl'),
    colorList:[
      {
        code:'01',
        color:'#ff5414',
        name:'红色'
      },{
        code:'02',
        color:'#ffc72c',
        name:'黄色'
      },
      {
        code:'03',
        color:'#6b95f7',
        name:'蓝色'
      },{
        code:'04',
        color:'#d7d5c6',
        name:'白色'
      },{
        code:'05',
        color:'#663200',
        name:'棕色'
      },
      {
        code:'06',
        color:'#666666',
        name:'灰色'
      },
      {
        code:'07',
        color:'#329900',
        name:'绿色'
      },{
        code:'08',
        color:'#222222',
        name:'黑色'
      },{
        code:'09',
        color:'#52edff',
        name:'12%双氧'
      },
       
      {
        code:'10',
        color:'#526164',
        name:'1%双氧'
      }
    ]
  },

   
  onShow: function (options) { 
   this.getDeviceList()
  },

   

getColorResidue:function(){
  
  _wxRequest.wxTonkenAjax({
    url: app.globalData.apiUrl + '/gds/protected/dyeVolume/findByDevId/'+this.data.deviceList[this.data.typeIndex].id,
    method: 'get', 
  }, (res) => {
    this.setData({
      colList:res.list
    })
    console.log(res,'余量') 
  })
},

//下拉刷新
onPullDownRefresh: function() {
  this.refreshData();
  wx.stopPullDownRefresh()
},

refreshData: function() {
  this.setData({
    pageNo: 1
  })
  this.getDeviceList()
},





bindPickerChange(e){
  var val=e.detail.value
  this.setData({
    typeIndex:val
  },()=>{
    this.getColorResidue();
  })
},






getDeviceList: function() {
  var params = {
    keyword: this.data.keyword, 
    pageNo: 1,
    typeId: wx.getStorageSync('currentTypeId'),
    pageSize: 999,
    noCountDye: 1
  }
   
  _wxRequest.wxTonkenAjax({
    url: app.globalData.apiUrl + '/gds/protected/device/findList',
    method: 'POST',
    data:params
  }, (res) => {
    let list = res.list.map(item => {
      if(item.stoName) {
        item.note += ` - ${item.stoName}`;
      }

      if(item.stoCreateName) {
        item.note += ` - ${item.stoCreateName}`;
      }
      return item;
    });
    
    this.setData({
      deviceList: list, 
    },()=>{
      if(list.length>0){
        this.getColorResidue() 
      }
      
    });
  })
},



})